﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：PurchaseList.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：采购信息管理显示，通过已审核与未审核
 * 作者：侯建
 * 创建日期：2011.04.12
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Jxym.wlkc2011.Module.Default.server.Purchase
{
    public partial class PurchaseList : System.Web.UI.Page
    {
        MsSqlDal<model.Purchase> iCom = new MsSqlDal<model.Purchase>();
        //MsSqlDal<model.Purchase> iCom = new MsSqlDal<model.Purchase>();
        PageBean pb = null;
        
        int modelid = 0;
        int type = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["limit"] != null && Request.Params["start"] != null)
            {
                if (Request.Params["type"] != null)
                {
                    type = Convert.ToInt32(Request.Params["Type"]);
                }
                if (type == 1)
                {
                    if (Request.Params["modelid"] != null)
                    {
                        modelid = Convert.ToInt32(Request.Params["modelid"]);
                    }
                    if (MyGet.GetPermissionsValidation(modelid, "S", Jxym.Common.Request.AdminID("user")))
                    {
                        pb = new PageBean();
                        IList<model.Purchase> list = iCom.GetPageList("ExamineState = 0 ", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        IList<model.Purchase> nList = new List<model.Purchase>();
                        pb.Count = iCom.GetPageCount("ExamineState = 0", null);
                        foreach (model.Purchase info in list)
                        {
                            info.PurchasePeople = MyGet.GetUserInfoByID(info.PurchasePeople).Name;
                            nList.Add(info);
                        }

                        pb.List = nList;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                    else
                    {
                        pb = new PageBean();
                        IList<model.Purchase> list = iCom.GetPageList("ExamineState = 0 and PurchasePeople = " + Jxym.Common.Request.AdminID("user"), null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        IList<model.Purchase> nList = new List<model.Purchase>();
                        pb.Count = iCom.GetPageCount("ExamineState = 0 and PurchasePeople = " + Jxym.Common.Request.AdminID("user"), null);
                        foreach (model.Purchase info in list)
                        {
                            info.PurchasePeople = MyGet.GetUserInfoByID(info.PurchasePeople).Name;
                            nList.Add(info);
                        }
                        pb.List = nList;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                }
                else
                {
                    if (Request.Params["modelid"] != null)
                    {
                        modelid = Convert.ToInt32(Request.Params["modelid"]);
                    }
                    if (MyGet.GetPermissionsValidation(modelid, "S", Jxym.Common.Request.AdminID("user")))
                    {
                        pb = new PageBean();
                        IList<model.Purchase> list = iCom.GetPageList("ExamineState != 0 ", null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        IList<model.Purchase> nList = new List<model.Purchase>();
                        pb.Count = iCom.GetPageCount("ExamineState != 0 ", null);
                        foreach (model.Purchase info in list)
                        {
                            info.PurchasePeople = MyGet.GetUserInfoByID(info.PurchasePeople).Name;
                            nList.Add(info);
                        }

                        pb.List = nList;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                    else
                    {
                        pb = new PageBean();
                        IList<model.Purchase> list = iCom.GetPageList("ExamineState != 0 and PurchasePeople = " + Jxym.Common.Request.AdminID("user"), null, Convert.ToInt32(Request.Params["start"]), Convert.ToInt32(Request.Params["limit"]));
                        IList<model.Purchase> nList = new List<model.Purchase>();
                        pb.Count = iCom.GetPageCount("ExamineState != 0 and PurchasePeople = " + Jxym.Common.Request.AdminID("user"), null);
                        foreach (model.Purchase info in list)
                        {
                            info.PurchasePeople = MyGet.GetUserInfoByID(info.PurchasePeople).Name;
                            nList.Add(info);
                        }

                        pb.List = nList;
                        Response.Write(JsonConvert.SerializeObject(pb, new JavaScriptDateTimeConverter()));
                    }
                }
            }
            else
            {
                Response.Write("{'Count':0,'List':[]}");
            }
        }
    }
}